<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <!--<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">-->
    <link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>武侯祠管理系统</title>

  
      <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
      <script type="text/javascript" src="js/materialize.min.js"></script>
    <style type="text/css">       
        body {
            background: #ddffcc;
        }
        
        .panel {
            margin: auto;
            margin-top: 100px;
            padding: 10%;
            padding-top: 2%;
            width: 510px;
            height: 510px;
            background-color: #fff;
            border-radius: 20px;
            box-shadow: 0px 0px 20px #60aa70;
        }
        
        #logo {
            margin-top: 30px;
            margin-bottom: 50px;
            text-align: center
        }
        
        #submit {
            width: 100px;
            margin: auto;
            margin-top: 50px;
        }

        #hint {
            color: #ff9922;
            margin-bottom: -20px;
            margin-top: 0px;
            height: 8px;
        }

        #form {
            margin-top: -20px;
        }

    </style>

</head>
<script>
    $(document).ready(
        function() {
        $("#submit").click(
        function() {                      //jQuery中的id选择器
            
            // var name = $("#username").val();                  //name
            var old_pwd = $("#old_password").val();
            var new_pwd = $("#new_password").val();
            var confirm_pwd = $("#confirm_password").val();
            
            //alert(name + "," + old_pwd + "," + new_pwd);
           //if (!checkInput("旧密码" , old_pwd) || !checkInput("姓名" , name)||!checkInput("新密码" , new_pwd)) {
             //   return
           // } 
         
          /*  if (name == "" || name == null) {
            alert("用户名不能为空");
            
           } 
                else if (  old_pwd == "" || old_pwd == null) {
                alert("密码不能为空");
                
                } 
        */

            var settings = {
                type: "POST",
                url: "http://192.168.21.14:8000/admin/update_password",             
                dataType: "json",
                data: {
                    module: "admin",                
                    action: "password",                
                    username: name,
                    old_password: old_pwd,
                    new_password: new_pwd,
                    confirm_password: confirm_pwd

                },
                error: function(XHR, textStatus, errorThrown) {
                    alert("网络错误");
                },
                success: function(data) {
                    json_data = JSON.parse(data);
                   
                    //alert(json_data.message);

                    document.getElementById("hint").innerHTML=json_data.message;
                    if(json_data.status==101||json_data.status==102||json_data.status==103||json_data.status==106)
                    { 
                        $("#username").val("");
                        $("#old_password").val("");
                        $("#new_password").val("");
                        $("#confirm_password").val("");
                    }
                    else if(json_data.status==107) 
                        {
                            window.location.href = "./login.html";
                        }

                    else  window.location.href = "./main2.html"; 
                },
            };
            
            $.ajax(settings);
        });
    });


</script>

<body class="light-green lighten-4">

    <nav class="myNav">
      <div class="nav-wrapper   light-green darken-4">
        <a href="" class="brand-logo"> 武侯祠管理系统</a>
        <ul id="nav-mobile" class="right hide-on-med-and-down">
          <li><a href="./main2.html">主页</a></li>
          <li><a href="./spot.html">景点</a></li>
          <li><a href="./food.html">美食</a></li>
          <li><a href="./toilet.html">厕所</a></li>
          <li><a href="./news.html">新闻</a></li>
          <li><a href="./broadcast.html">广播</a></li>
          <li><a href="./feedback.html">反馈</a></li>
          <li><a href="./password.html">设置</a></li>
        </ul>
      </div>
    </nav>

    <div class="container ">
        <div class="panel ">

            <h4 id="logo">设置<small>-修改密码</small></h4>
            
            <form>
                
                <input type="hidden" name="module" value="admin">
                <input type="hidden" name="action" value="login">
                
                <div class="form-group">
                    <label for="old_password">旧密码</label>
                    <input type="password" class="form-control" id="old_password" name="old_password" placeholder="旧密码">
                </div>
                  <div class="form-group">
                    <label for="new_password">新密码</label>
                    <input type="password" class="form-control" id="new_password" name="new_password" placeholder="新密码">
                </div>
                 <div class="form-group">
                    <label for="confirm_password">确认密码</label>
                    <input type="password" class="form-control" id="confirm_password" name="confirm_password" placeholder="确认密码">
                </div>

                <div>
                    <p id="hint"></p>
                </div>

                <button type="button" class="btn btn-primary btn-block light-green" id="submit">修改</button>
            </form>

        </div>
    </div>

</body>

</html>

